package com.hgxd.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.sql.Blob;
import java.sql.SQLException;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: FSD
 * @Created 2023/11/1 11:16
 * @description
 **/
@Configuration
@Component
public class BlobConfig {

    public String convertBlobToString(Blob blob){

        String result = "";
        try {
            ByteArrayInputStream msgContent =(ByteArrayInputStream) blob.getBinaryStream();
            byte[] byte_data = new byte[msgContent.available()];
            msgContent.read(byte_data, 0,byte_data.length);
            result = new String(byte_data);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return result;
    }
}
